<?php

namespace App\B2BProject\Admin\Authority\Rbac;

use Illuminate\Database\Eloquent\Model;

class Role extends Model
{
    protected $fillable = ['name', 'display_name', 'description'];

    public static function boot()
    {
        parent::boot();

        static::deleting(function($role) {
            if (!method_exists(Role::class, 'bootSoftDeletingTrait')) {
                $role->users()->sync([]);
                $role->permissions()->sync([]);
            }

            return true;
        });
    }

    public function users()
    {
        return $this->belongsToMany('App\B2BProject\Admin\Administrator');
    }

    public function permissions()
    {
        return $this->belongsToMany('App\B2BProject\Admin\Authority\Rbac\Permission');
    }
}
